/**
 * 
 */
package be.luys.almacen.gui;

import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.BevelBorder;
import be.luys.almacen.gui.logic.ApplicationManager;
import be.luys.almacen.gui.logic.LoadingListener;

/**
 * @author fks/Erik Luys
 */
public class StatusPanel extends JPanel implements LoadingListener
{

    private static StatusPanel instance;
    private static final int PROGRESS_MAX = 100;

    private static final int PROGRESS_MIN = 0;

    /**
     * The UID.
     */
    private static final long serialVersionUID = 1L;

    public static synchronized StatusPanel getPanel()
    {
        if (instance == null)
        {
            instance = new StatusPanel();
        }
        return instance;
    }

    private final JLabel lblStatus = new JLabel("Starting application...");
    private final JProgressBar progressBar = new JProgressBar();

    private StatusPanel()
    {
        super(new BorderLayout());
        add(this.lblStatus, BorderLayout.CENTER);
        add(this.progressBar, BorderLayout.EAST);
        setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

        this.progressBar.setMinimum(PROGRESS_MIN);
        this.progressBar.setMaximum(PROGRESS_MAX);

        ApplicationManager.getManager().register(this);
    }

    // ===========================================================================
    /* (non-Javadoc)
     * @see be.luys.almacen.gui.logic.LoadingListener#loading(java.lang.String, double)
     */
    @Override
    public void loading(final String text, final double progress)
    {
        this.lblStatus.setText(text);
        this.progressBar.setValue((int) (progress * PROGRESS_MAX));
    }

}
